{**
 * Pharmacy edit
 *
 * @package   OpenEMR
 * @link      http://www.open-emr.org
 * @author    Brady Miller <brady.g.miller@gmail.com>
 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
 * @license   https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
 *}
{if $ERROR}
    <div class="alert alert-danger">{$ERROR|escape:'html'}</div>
{else}
    <form name="provider" method="post" action="{$FORM_ACTION}" class='form-horizontal' onsubmit="return top.restoreSession()">
        <!-- it is important that the hidden form_id field be listed first, when it is called it populates any old information attached with the id, this allows for partial edits
                    if it were called last, the settings from the form would be overwritten with the old information-->
        <input type="hidden" name="form_id" value="{$ins->id|escape:'html'}" />

        <table class="table table-responsive table-striped">

        <tr><td colspan="5" style="border-style:none;" class="bold">
            {$provider->get_name_display()|escape:'html'}
        </td></tr>

        <tr  class="showborder_head">
            <th class="small">{xl t='Company Name'|escape:'html'}</th>
            <th class="small">{xl t='Provider Number'|escape:'html'}</th>
            <th class="small">{xl t='Rendering Provider Number'|escape:'html'}</th>
            <th class="small">{xl t='Group Number'|escape:'html'}</th>
        </tr>
        {foreach name=inums item=num_set from=$provider->get_insurance_numbers()}
            <tr>
                <td valign="middle">
                    <a href="{$CURRENT_ACTION}action=edit&id={$num_set->get_id()|escape:'html'}&showform=true" onclick="top.restoreSession()">
                        {$num_set->get_insurance_company_name()|escape:'html'}&nbsp;
                    </a>
                </td>
                <td>{$num_set->get_provider_number()|escape:'html'}&nbsp;</td>
                <td>{$num_set->get_rendering_provider_number()|escape:'html'}&nbsp;</td>
                <td>{$num_set->get_group_number()|escape:'html'}&nbsp;</td>
            </tr>
        {foreachelse}
        <tr>
            <td colspan="5">{xl t='No entries found, use the form below to add an entry.'|escape:'html'}</td>
        </tr>
        {/foreach}

        <tr> <td style="border-style:none;" colspan="5">
            <a href="{$CURRENT_ACTION}action=edit&id=&provider_id={$provider->get_id()|escape:'html'}&showform=true"
                class="btn btn-default btn-add" onclick="top.restoreSession()">
                <span>{xl t='Add New'|escape:'html'}
            </a>
        </td> </tr>
        </table>

        {if $show_edit_gui}
            <div class="alert alert-info">
                {if $ins->get_id() eq ""}
                    {xl t='Add Provider Number'|escape:'html'}
                {else}
                    {xl t='Update Provider Number'|escape:'html'}
                {/if}
            </div>
            <div class="form-group">
                <label for="insurance_company_id" class="control-label col-sm-2">{xl t='Insurance Company'|escape:'html'}</label>
                <div class="col-sm-8">
                    {if $ins->get_id() eq ""}
                        <select id="insurance_company_id" name="insurance_company_id" class="form-control">
                            {html_options options=$ic_array values=$ic_array selected=$ins->get_insurance_company_id()}
                        </select>
                    {else}
                        <span id="insurance_company_id" class="form-control-static">
                            {$ins->get_insurance_company_name()|escape:'html'}
                        </span>
                    {/if}
                </div>
            </div>
            <div class="form-group">
                <label for="provider_number" class="control-label col-sm-2">{xl t='Provider Number'|escape:'html'}</label>
                <div class="col-sm-8">
                    <input type="text" id="provider_number" name="provider_number" class="form-control" value="{$ins->get_provider_number()|escape:'html'}" onKeyDown="PreventIt(event)">
                </div>
            </div>
            <div class="form-group">
                <label for="provider_number_type" class="control-label col-sm-2">{xl t='Provider Number (Type)'}</label>
                <div class="col-sm-8">
                    <select id="provider_number_type" name="provider_number_type" class="form-control">
                        {html_options options=$ic_type_options_array values=$ins->provider_number_type_array selected=$ins->get_provider_number_type()}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="rendering_provider_number" class="control-label col-sm-2">{xl t='Rendering Provider Number'|escape:'html'}</label>
                <div class="col-sm-8">
                    <input type="text" id="rendering_provider_number" name="rendering_provider_number" class="form-control" value="{$ins->get_rendering_provider_number()|escape:'html'}" onKeyDown="PreventIt(event)">
                </div>
            </div>
            <div class="form-group">
                <label for="rendering_provider_number_type" class="control-label col-sm-2">{xl t='Rendering Provider Number (Type)'|escape:'html'}</label>
                <div class="col-sm-8">
                    <select id="rendering_provider_number_type" name="rendering_provider_number_type" class="form-control">
                        {html_options options=$ic_rendering_type_options_array values=$ins->rendering_provider_number_type_array selected=$ins->get_rendering_provider_number_type()}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="group_number" class="control-label col-sm-2">{xl t='Group Number'|escape:'html'}</label>
                <div class="col-sm-8">
                    <input type="text" id="group_number" name="group_number" value="{$ins->get_group_number()|escape:'html'}" onKeyDown="PreventIt(event)">
                </div>
            </div>
            <div class="btn-group col-sm-offset-2">
                {if $ins->get_id() eq ""}
                    <a href="javascript:submit_insurancenumbers_add();" class="btn btn-default btn-save" onclick="top.restoreSession()">
                        {xl t='Save'|escape:'html'}
                    </a>
                {else}
                    <a href="javascript:submit_insurancenumbers_update();" class="btn btn-default btn-save" onclick="top.restoreSession()">
                        {xl t='Save'|escape:'html'}
                    </a>
                {/if}
                <a href="controller.php?practice_settings&insurance_numbers&action=list" class="btn btn-link btn-cancel" onclick="top.restoreSession()">
                    {xl t='Cancel'|escape:'html'}
                </a>
            </div>

        {else}
            <input type="hidden" name="provider_number" value="{$ins->get_provider_number()|escape:'html'}" />
            <input type="hidden" name="provider_number_type" value="{$ins->get_provider_number_type()|escape:'html'}" />
            <input type="hidden" name="rendering_provider_number" value="{$ins->get_rendering_provider_number()|escape:'html'}" />
            <input type="hidden" name="rendering_provider_number_type" value="{$ins->get_rendering_provider_number_type()|escape:'html'}" />
            <input type="hidden" name="group_number" value="{$ins->get_group_number()|escape:'html'}" />
        {/if}

        <input type="hidden" name="id" value="{$ins->id|escape:'html'}" />
        <input type="hidden" name="provider_id" value="{$ins->get_provider_id()|escape:'html'}" />
        <input type="hidden" name="process" value="{$PROCESS|escape:'html'}" />
    </form>
{/if}

{literal}
<script language="javascript">
function submit_insurancenumbers_update() {
    top.restoreSession();
    document.provider.submit();
}
function submit_insurancenumbers_add() {
    top.restoreSession();
    document.provider.submit();
    //Z&H Removed redirection
}

function Waittoredirect(delaymsec) {
 var st = new Date();
 var et = null;
 do {
 et = new Date();
 } while ((et - st) < delaymsec);

 }
</script>
<style type="text/css">
text,select {font-size:9pt;}
</style>
{/literal}